package com.hanhai;


import java.time.Duration;
import java.time.LocalDateTime;

/**
 * @Author weijingchen
 * @Date 2025/5/27 6:44
 * @Version 1.0.0
 */
public class DurationTest {
    public static void main(String[] args) {
        //1、计算秒和纳秒
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime localDateTime = LocalDateTime.of(2025, 4, 20, 12, 11, 18);
        //获取两个时间之间的秒数,后面的参数减前面的参数
        Duration between = Duration.between( localDateTime,now);
        System.out.println("相差时间间隔对象"+between);

        System.out.println("两个时间相差的天数"+between.toDays());
        System.out.println("两个时间相差的小时数"+between.toHours());
        System.out.println("两个时间相差的分钟数"+between.toMinutes());
        System.out.println("两个时间相差的秒数"+between.getSeconds());
        System.out.println("两个时间相差的毫秒数"+between.toMillis());
        System.out.println("两个时间相差的纳秒数"+between.toNanos());
    }
}
